package org.jgs1904.practice;

import java.util.Scanner;

/**
 * @author: 默苍璃
 * @date: 2022-09-09 11:10
 * <p>
 * 使用while计算从m到n的和：
 */
public class While {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        System.out.println("输入第一个数:");
        int one = scanner.nextInt();
        System.out.println("输入第二个数:");
        int tow = scanner.nextInt();

        //多种业务逻辑未处理,例如:第二个数比第一个小
        int sum = 0;
        while (true) {
            sum += one;
            one++;
            if (one > tow) {
                break;
            }
        }
        System.out.println(sum);


        //方法二
        int sum1 = 0;
        while (one <= tow) {
            sum1 += one;
            one++;
        }
        System.out.println(sum1);

        scanner.close();
    }

}
